import { delArrChildren } from "@/utils/array";
import { commonIndicatorObj,userArr,behaviourArr,modelArr } from "./mockJson";
export default {
  data() {
    return {
      modelOptions: [],
      userOptions: [],
      behaviourOptions: [],
      commonIndicatorObj: {},
    };
  },
  /**
   * 把异步接口，改为本地伪造假数据，方便本地调试。正常情况下应为接口请求返回。
   */
  methods: {
    async getCommonIndicator() {
      setTimeout(()=>{
        this.commonIndicatorObj = commonIndicatorObj;   
      })
    },
    async getModelOptions() {
        const modelArray = modelArr;
        delArrChildren(modelArray);
        setTimeout(() => {
          this.modelOptions = modelArray;
        });

    },
    async getUserOptions() {
      const processData =[];
      userArr.forEach(element => {
        let eleChildren = []
        const { code, children } = element
        if (code === 'user_tag_group_header' || code === 'user_group_header') {
          element.disabled = 'disabled'
          eleChildren = JSON.parse(JSON.stringify(children))
          element.children = []
        }
        processData.push(element)
        for (let i = 0; i < eleChildren.length; i++) {
          processData.push(eleChildren[i])
        }
      });
      processData.unshift({ code: 'basic_self', name: "基础属性", children: [], disabled: "disabled" })
      delArrChildren(processData);
        setTimeout(()=>{
          this.userOptions = processData;
        })
    },
    async getBehaviourOptions() {
      const behaviourArray  = behaviourArr
      delArrChildren(behaviourArray);
      setTimeout(() => {
        this.behaviourOptions = behaviourArr;
      });
      
    },
  },
};
